package org.mule.robo;

import java.util.regex.Matcher;

public class CommandFactory
{

    private static final String MOVE = "move";
    private static final String PILE = "pile";
    private static final String ONTO = "onto";
    private static final String OVER = "over";

    public static Command create(Matcher matcher)
    {
        if (MOVE.equals(matcher.group(1)) && ONTO.equals(matcher.group(3)))
        {
            return new MoveOntoCommand(Integer.parseInt(matcher.group(2)),
                                       Integer.parseInt(matcher.group(4)));
        }
        else if (MOVE.equals(matcher.group(1)) && OVER.equals(matcher.group(3)))
        {
            return new MoveOverCommand(Integer.parseInt(matcher.group(2)),
                                       Integer.parseInt(matcher.group(4)));
        }
        else if (PILE.equals(matcher.group(1)) && ONTO.equals(matcher.group(3)))
        {
            return new PileOntoCommand(Integer.parseInt(matcher.group(2)),
                                       Integer.parseInt(matcher.group(4)));
        }
        else if (PILE.equals(matcher.group(1)) && OVER.equals(matcher.group(3)))
        {
            return new PileOverCommand(Integer.parseInt(matcher.group(2)),
                                       Integer.parseInt(matcher.group(4)));
        }

        throw new IllegalArgumentException("bad command input");
    }

}
